package com.bite.system.controller.question;

import com.bite.common.core.controller.BaseController;
import com.bite.common.core.domain.R;
import com.bite.common.core.domain.TableDataInfo;
import com.bite.system.domain.question.Question;
import com.bite.system.domain.question.dto.QuestionAddDTO;
import com.bite.system.domain.question.dto.QuestionEditDTO;
import com.bite.system.domain.question.dto.QuestionQueryDTO;
import com.bite.system.domain.question.vo.QuestionDetailVO;
import com.bite.system.domain.question.vo.QuestionVO;
import com.bite.system.service.question.IQuestionService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/question")
@Tag(name="题目管理接口")
//BaseController封装了就是数据库查找，删除，增加影响的行数，看是否添加成功
public class QuestionController extends BaseController {

    //接口概述,接口地址,请求参数,请求方法(Get(查询),Post(新增),Put(增加),DeLETE(删除))
    @Autowired
    private IQuestionService questionService;
    @GetMapping("/list")
    public TableDataInfo list(QuestionQueryDTO questionQueryDTO){
        List<QuestionVO>questionVOList=questionService.list(questionQueryDTO);
        return   getTableDataInfo(questionVOList);
    }
    //question/add
    @PostMapping("/add")
    public R<Void> add(@RequestBody QuestionAddDTO questionAddDTO ){
        //toR判断行数的
     return toR(questionService.add(questionAddDTO));
    }

    //question/detail
    @GetMapping("/detail")
    public R<QuestionDetailVO> detail(Long questionId){
     return R.ok(questionService.detail(questionId));
    }
    //question/edit
    @PutMapping("/edit")
    public   R<Void>  edit(@RequestBody  QuestionEditDTO questionEditDTO){
        return toR(questionService.edit(questionEditDTO));
    }
    @DeleteMapping("/delete")
    public R<Void> delete(Long questionId){
       return toR(questionService.delete(questionId));
    }



}
